package com.yksj.healthtalk.comm;

import org.universalimageloader.core.DisplayImageOptions;
import org.universalimageloader.core.ImageLoader;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.yksj.healthtalk.net.socket.SmartFoxClient;
import com.yksj.healthtalk.ui.MainTabUI;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.doctor.DoctorInterviewServiceActivity;
import com.yksj.healthtalk.ui.doctor.DoctorMainFragment;
import com.yksj.healthtalk.ui.doctor.DoctorTimeServiceActivity;
import com.yksj.healthtalk.ui.doctorstation.DoctorHomeMainActivity;
import com.yksj.healthtalk.ui.doctorstation.DoctorMarkTalkFragment;
import com.yksj.healthtalk.ui.doctorstation.DoctorServiceAddTime;
import com.yksj.healthtalk.ui.doctorstation.DoctorServiceTimeListActivity;
import com.yksj.healthtalk.ui.doctorstation.DoctorSettingActivity;
import com.yksj.healthtalk.ui.friend.DoctorMainActivity;
import com.yksj.healthtalk.ui.home.MyDoctorMoreActivity;
import com.yksj.healthtalk.ui.home.MyHomeMainActivity;
import com.yksj.healthtalk.ui.home.SalonListActivity;
/**
 * 引导页(加载的都是本地图片)
 * @author jack_tang
 *			intent=new Intent(this, GuidePagerFragmentActivity.class);
			intent.putExtra("type",0);
			startActivity(intent);
 */
public class GuidePagerFragmentActivity extends BaseFragmentActivity implements OnClickListener {
	ViewPager mViewPager;
	DisplayImageOptions mDisplayImageOptions;
	ImageLoader mImageLoader;
	private int [] arrays;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.gui_pager_fragment_layout);
		mViewPager = (ViewPager)findViewById(R.id.pager);
		mImageLoader = ImageLoader.getInstance();
		String className= getIntent().getStringExtra("className");
		
		if(className.equals(MainTabUI.class.getName())){
			if(!SmartFoxClient.getLoginUserInfo().isDoctor()){//主界面
				arrays = new int[]{R.drawable.introduce_huan_1,R.drawable.introduce_huan_3,R.drawable.introduce_huan_2,R.drawable.introduce_huan_4,R.drawable.introduce_huan_5};	
			}else{
				arrays = new int[]{R.drawable.introduce_yi_1,R.drawable.introduce_yi_2,R.drawable.introduce_yi_3,R.drawable.introduce_yi_4};
			}
		}else if(className.equals(DoctorMainFragment.class.getName())){//医生馆
			arrays = new int[]{R.drawable.introduce1,R.drawable.introduce2};
		}else if(className.equals(DoctorMainActivity.class.getName())){//医生资料
			arrays = new int[]{R.drawable.introduce3,R.drawable.introduce19};
		}else if(className.equals(DoctorTimeServiceActivity.class.getName())){//网上咨询
			arrays = new int[]{R.drawable.introduce_wang_1,R.drawable.introduce_wang_2,R.drawable.introduce_wang_3};
		}else if(className.equals(DoctorInterviewServiceActivity.class.getName())){//门诊预约
			arrays = new int[]{R.drawable.introduce_men_1,R.drawable.introduce_men_2,R.drawable.introduce_men_3};
		}else if(className.equals(DoctorMarkTalkFragment.class.getName()+"_1")){//门诊预约(医生)
			arrays = new int[]{R.drawable.introduce_men_yi_1,R.drawable.introduce_men_yi_2};
		}else if(className.equals(DoctorMarkTalkFragment.class.getName()+"_2")){//网上咨询(医生)
			arrays = new int[]{R.drawable.introduce_wang_yi_1,R.drawable.introduce_wang_yi_2};
		}else if(className.equals(MyHomeMainActivity.class.getName())){//我的壹健康
			arrays = new int[]{R.drawable.introduce15};
		}else if(className.equals(DoctorHomeMainActivity.class.getName())){//我的诊所
			arrays = new int[]{R.drawable.introduce_zhensuo_1,R.drawable.introduce_zhensuo_2,R.drawable.introduce_zhensuo_3,R.drawable.introduce9,};
//		}else if(className.equals(DoctorCommonServiceActivity.class.getName())){//VIP服务
//			arrays = new int[]{R.drawable.introduce22};
		}else if(className.equals(SalonListActivity.class.getName())){//我的话题
			arrays = new int[]{R.drawable.introduce20};
		}else if(className.equals(MyDoctorMoreActivity.class.getName())){//我的医生更多
			arrays = new int[]{R.drawable.introduce21};
//		}else if(className.equals(SelectPaymentOptionActivity.class.getName())||
//			className.equals(SalonSelectPaymentOptionActivity.class.getName())){//选择支付方式
//			arrays = new int[]{R.drawable.introduce10};
		}else if(className.equals(CommonExplainActivity.class.getName())){//取消预约原因
			arrays = new int[]{R.drawable.introduce14};
		}else if(className.equals(DoctorSettingActivity.class.getName())){//服务设置
			arrays = new int[]{R.drawable.introduce8};
		}else if(className.equals(DoctorServiceTimeListActivity.class.getName())){//服务时段设置
			arrays = new int[]{R.drawable.introduce7};
		}else if(className.equals(DoctorServiceAddTime.class.getName())){//添加服务时段
			arrays = new int[]{R.drawable.introduce6};
		}else if(className.equals(DoctorServiceAddTime.class.getName()+"_1")){//编辑服务时段(门诊)
			arrays = new int[]{R.drawable.introduce13};
		}else if(className.equals(DoctorServiceAddTime.class.getName()+"_2")){//编辑服务时段(网上咨询)
			arrays = new int[]{R.drawable.introduce12,};
		}
		
		GalleryPagerAdapter galleryPagerAdapter = new GalleryPagerAdapter(arrays);
		mViewPager.setAdapter(galleryPagerAdapter);
	}
	
	private class GalleryPagerAdapter extends  PagerAdapter{
		int[] images;
		public GalleryPagerAdapter(int[] urls) {
			images = urls;
		}
		
		@Override
		public void destroyItem(View container, int position, Object object) {
			((ViewPager)container).removeView((View)object);
		}
		
		@Override
		public int getCount() {
			return images.length;
		}

		@Override
		public Object instantiateItem(View container, int position) {
			ImageView imageView=(ImageView) View.inflate(getApplicationContext(), R.layout.gui_pager_image_item, null);
			imageView.setId(10000);
			imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			DisplayImageOptions options=new DisplayImageOptions.Builder(getApplicationContext()).showImageForEmptyUri(images[position])
					.showStubImage(images[position]).build();
			mImageLoader.displayImage("", imageView, options);
			((ViewPager)container).addView(imageView,0);
			imageView.setOnClickListener(GuidePagerFragmentActivity.this);
			return imageView;
		}
		@Override
		public boolean isViewFromObject(View view, Object arg1) {
			return view == arg1;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case 10000:
			if(mViewPager.getCurrentItem()!=arrays.length-1){
				mViewPager.setCurrentItem(mViewPager.getCurrentItem()+1,false);
			}else{
				GuidePagerFragmentActivity.this.finish();
			}
			break;
		}
		
	}
}
